package huawei.window;

public class J643 {
    public static void main(String[] args) {
        System.out.println(findMaxAverage(new int[]{-1},1));
    }
    public static double findMaxAverage(int[] nums, int k) {
        /**
         * 思路:滑动窗口,更新总和.
         * 优化,sum,avg 正相关, 比较直接使用和,最终输出结果再计算avg
         */
        int sum =0;
        int sumMax=Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            sum+=nums[i];
            if(i+1>=k){
                sumMax=Math.max(sumMax,sum);
                sum-=nums[i+1-k];
            }
        }
        return ((double)sumMax)/k;
    }
}
